package main

import (
	"fmt"
	"math"
)

func main() {
	var a int = 100
	var b int = 200
	var ret int
	ret = max(a, b)
	fmt.Printf("最大：%d\n", ret)
	s1, s2 := swap("s1", "s2")
	fmt.Println(s1, s2)
	/*这里是值传递，所以方法内交换不是实际影响  a和b的值*/
	var temp int
	temp = swap1(a, b)
	fmt.Println(a, b, temp)
	/*这里是引用传递，所以方法内交换是实际影响  a和b的值*/
	swap2(&a, &b)
	fmt.Println(a, b)
	/*直接声明函数变量*/
	getSquareRoot := func(x float64) float64 {
		return math.Sqrt(x)
	}
	fmt.Println(getSquareRoot(9))
	fmt.Println()
	/**/
	nextNumber := getSquence()
	/* 调用 nextNumber 函数，i 变量自增 1 并返回 */
	fmt.Println(nextNumber())
	fmt.Println(nextNumber())
	fmt.Println(nextNumber())
	/* 创建新的函数 nextNumber1，并查看结果 */
	nextNumber1 := getSquence()
	fmt.Println(nextNumber1())
	fmt.Println(nextNumber1())
	/**/
	var c1 Circle
	c1.radius = 10.00
	fmt.Println("圆的面积 = ", c1.getArea())

}

func swap(x, y string) (string, string) {
	return y, x
}

func max(num1, num2 int) int {
	var result int
	if num1 > num2 {
		result = num1
	} else {
		result = num2
	}
	return result
}

/*值传递*/
func swap1(x, y int) int {
	var temp int
	temp = x
	x = y
	y = temp
	return temp
}

/*引用传递*/
func swap2(x *int, y *int) {
	var temp int
	temp = *x
	*x = *y
	*y = temp
}

func getSquence() func() int {
	i := 0
	return func() int {
		i += 1
		return i
	}
}

type Circle struct {
	radius float64
}

func (c Circle) getArea() float64 {
	return 3.14 * c.radius * c.radius
}
